<!-- 登录界面 -->
<template>
  <div class="login">
    <div class="login-box">
      <el-form :model="loginForm" :rules="rules" ref="loginForm">
        <h3 class="title">欢迎登录</h3>
        <el-form-item prop="staffNumber">
          <el-input
              placeholder="userName"
              type="text"
              tabindex="1"
              autocomplete="on"
              v-model="loginForm.staffNumber"
          ></el-input>
        </el-form-item>

        <el-form-item prop="password">
          <el-input
              type="password"
              v-model="loginForm.password"
              autocomplete="off"
              placeholder="password"
          ></el-input>
        </el-form-item>
        <el-button
            type="primary"
            @click="submitForm('loginForm')"
            style="width: 100%; margin-bottom: 30px"
        >登录</el-button
        >
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    const validateName = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入账号'))
      } else {
        callback()
      }
    }
    const validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'))
      }
      callback()
    }
    return {
      loginForm: {
        staffNumber: '',
        password: ''
      },
      rules: {
        name: [{
          validator: validateName, trigger: 'blur'
        }],
        checkPass: [
          { validator: validatePass, trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 登录提交
    submitForm () {
      // console.log(this.loginForm)
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          this.$router.push('/home')
          // alert('submit!')
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style scoped>
.login {
  width: 100%;
  height: 100vh;
  background-color: rgb(45, 58, 75);
  display: flex;
  justify-content:center;
  align-items: center;
}
.login-box {
  width: 400px;
  height: 350px;
}
.title {
  font-size: 26px;
  color: #eee;
  margin: 0 auto 40px auto;
  text-align: center;
  font-weight: bold;
}

</style>
